package com.wanpinghui.wphlibrary.model.order;

import com.wanpinghui.wphlibrary.common.IWPHApi;
import com.wanpinghui.wphlibrary.model.order.bean.OrderItemBean;
import com.wanpinghui.wphlibrary.model.order.bean.OrderRemarkBean;
import com.wanpinghui.wphlibrary.model.order.bean.PageDataBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit.Network;
import retrofit.callback.YRequestCallback;
import retrofit.callback.YunShlAction;
import retrofit.callback.YunShlResult;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 功能说明：
 * Created by caitiangui
 * 创建时间： 2018/1/2.
 */

public class OrderServiceImp implements OrderService {

    @Override
    public void searchPersonalList(int page,int related_id, final YRequestCallback<PageDataBean<OrderItemBean>> callback) {

        Network.getYSApi(IWPHApi.class).searchPersonalList(page,related_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<YunShlResult<PageDataBean<OrderItemBean>>>() {
                    @Override
                    public void call(YunShlResult<PageDataBean<OrderItemBean>> result) {
                        if (callback != null){
                            if (result.isSuccess()){
                                callback.onSuccess(result.body);
                            }else {
                                callback.onFailed(0,result.msg);
                            }
                        }
                    }
                },new YunShlAction<Throwable>(callback));
    }

    @Override
    public void addOrderRemark(OrderRemarkBean newInfo, final YRequestCallback<List<OrderRemarkBean>> callback) {
        Network.getYSApi(IWPHApi.class).addOrderRemark(newInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<YunShlResult<List<OrderRemarkBean>>>() {
                    @Override
                    public void call(YunShlResult<List<OrderRemarkBean>> result) {
                        if (callback != null){
                            if (result.isSuccess()){
                                callback.onSuccess(result.body);
                            }else {
                                callback.onFailed(0,result.msg);
                            }
                        }
                    }
                },new YunShlAction<Throwable>(callback));
    }

    @Override
    public void getOrderDetail(int orderId, final YRequestCallback<OrderItemBean> callback) {
        Network.getYSApi(IWPHApi.class).getOrderDetail(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<YunShlResult<OrderItemBean>>() {
                    @Override
                    public void call(YunShlResult<OrderItemBean> result) {
                        if (callback != null){
                            if (result.isSuccess()){
                                callback.onSuccess(result.body);
                            }else {
                                callback.onFailed(0,result.msg);
                            }
                        }
                    }
                },new YunShlAction<Throwable>(callback));
    }


}
